package org.example.demo;

import org.example.utils.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class demo6_Delete {
    public static void main(String[] args) {
        //声明对象
        Connection connection = null;
        PreparedStatement statement = null;

        try {
            connection = DBUtil.getConnection();
            String sql = "delete from users where id = ?";
            statement = connection.prepareStatement(sql);
            System.out.println("请输入id");
            Scanner scanner = new Scanner(System.in);
            long inputId = scanner.nextLong();

            statement.setLong(1,inputId);

            int row = statement.executeUpdate();
            if (row == 1){
                System.out.println("删除成功");
            }else {
                System.out.println("删除失败");
            }

        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            DBUtil.close(null,statement,connection);
        }
    }
}
